package com.wise.service.portal.content.regions;

import com.wise.entities.content.Region;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import com.wise.framework.validation.Precondition;
import com.wise.summer.v1.portal.content.regions.ListRegionsByLevel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;

import static com.wise.entities.content.Region._level;
import static com.wise.model.content.ContentErrMsgs.Err_000300030008;


@Slf4j
@Service
@SummerService
public class ListRegionsByLevelService implements SummerServiceBean<ListRegionsByLevel> {
    @Override
    public void sum(ListRegionsByLevel summer) {
        Precondition.checkNotNull(summer.getLevel(), Err_000300030008);

        SqlSelect sql = SqlSelect.selec("*").fromClassName(Region.class).eq(_level, summer.getLevel());
        List<Region> result = DaoList.s(Region.class, sql);

        summer.setSummerResult(result);
    }
}
